package com.naiterui.ehp.bs.emr.entity.mongo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.naiterui.ehp.bp.utils.date.DateUtil;
import lombok.Data;
import lombok.ToString;
import org.springframework.data.annotation.Id;

import java.util.Date;
import java.util.Optional;

/**
 * 实体基本属性
 *
 * @author wangzehao
 * @date 2018/11/21 11:17 AM
 * @since 1.0.0
 */
@Data
@ToString
@SuppressWarnings("WeakerAccess")
public abstract class BaseMedicalRecord implements java.io.Serializable {
    private static final long serialVersionUID = 1706865260308793769L;
    /**
     * <主键>
     */
    @Id
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String id;

    /**
     * 病历失效状态 0：正常 1：删除
     */
    private Integer invalid;
    /**
     * 病历失效时间
     */
    @JsonFormat(pattern = DateUtil.DATE_TIME)
    private Date invalidTime;
    /**
     * <创建时间>
     */
    @JsonInclude(JsonInclude.Include.NON_DEFAULT)
    private Date createAt;
    /**
     * <创建人>
     */
    @JsonInclude(JsonInclude.Include.NON_DEFAULT)
    private String createBy;
    /**
     * <修改时间>
     */
    @JsonInclude(JsonInclude.Include.NON_DEFAULT)
    private Date changeAt;
    /**
     * <修改人>
     */
    @JsonInclude(JsonInclude.Include.NON_DEFAULT)
    private String changeBy;

    public void initSave(String createBy) {
        setInvalid(MedicalRecord.INVALID_STATUS_NORMAL);
        setCreateAt(Optional.ofNullable(getCreateAt()).orElse(new Date()));
        setChangeAt(new Date());
        setCreateBy(createBy);
        setChangeBy(createBy);
    }


}
